var fourSum = function(nums, target) {
  nums.sort((a,b)=>a-b)
  const l = nums.length
  let res = []
  const dfs = (index,arr,target,count) => {
      if(target === 0 && arr.length===4) {
          res.push(arr)
          return
      }
      //剪枝
      if( arr.length > 4) {
        return
      }
      // 剪枝 最小值大于target
      if(nums[index] * count> target) return
      // 
      if(nums[l-1] * count < target) return
      for(var i = index;i<l;i++) {
          if(i>index && nums[i]==nums[i-1]) continue
          arr.push(nums[i])
          dfs(i+1,[...arr],target - nums[i],count-1)
          arr.pop()
      }
  }
  dfs(0,[],target,4)
  return res
};
let nums = [-1,0,1,2,-1,-4]
let target = -1
console.log(fourSum(nums,target));